// __PUBLIC__/admin/js/page/admin/global/siteopt
require(['../../common'], function() {
  require(['global.siteopt'])
})

define('global.siteopt', [
  'jquery',
  'jqp/validate'
], function($) {
  'use strict';

  function checkUrl(field) {
    var val = $.trim(field.value)
    var re = /^https?:\/\/\S+/i
    var result = re.test(val) ? true : lang.webSiteUrlCheck
    return result
  }

  function checkNumber(field) {
    var val = $.trim(field.value)
    var re = /^[1-9]\d*$/i
    // TODO: 缺少 lang, 故 name 改为 _length 以不验证
    var result = re.test(val) ? true : lang.webSiteUrlCheck
    return result
  }

  $('#J_form').validate({
    classPlace: '.kv',
    errorPlace: '.kv-error',
    errors: {
      'site_url': {
        url: checkUrl
      },
      'admin_email': {
        email: lang.emailFormatErrors
      },
      '_length': {
        number: checkNumber
      }
    }
  })

})
